﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;

namespace ERPStore.Offers.Repositories
{
	public class OffersDbContext : DbContext
	{
		public OffersDbContext()
			: this("name = ERPStoreConnectionString")
		{
		}

		public OffersDbContext(string connectionString)
			: base(connectionString)
		{
			var csBuilder = new SqlConnectionStringBuilder(this.Database.Connection.ConnectionString);
			csBuilder.ApplicationName = this.GetType().Assembly.FullName + "," + System.Environment.MachineName;
			this.Database.Connection.ConnectionString = csBuilder.ConnectionString;
			this.Configuration.AutoDetectChangesEnabled = false;
			this.Configuration.ProxyCreationEnabled = false;
		}

		public DbSet<Datas.OfferedProductData> OfferedProducts { get; set; }
		public DbSet<Datas.OfferData> Offers { get; set; }

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			base.OnModelCreating(modelBuilder);
			modelBuilder.Configurations.Add(new Mapping.OfferedProductMap());
			modelBuilder.Configurations.Add(new Mapping.OfferMap());
		}
	}
}
